//
//  BNDOfficeDocCTtachmentView.m
//  OfficeDoc
//
//  Created by pie on 2022/4/3.
//  Copyright © 2022 pie. All rights reserved.
//

#import "BNDOfficeDocCTtachmentView.h"
#import "BNDCTtachmentView.h"
#import "LVUIUtils.h"
#import "BNDOfficeDocKit.h"

@interface BNDOfficeDocCTtachmentView ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) NSMutableArray *pdfListData;
@end

@implementation BNDOfficeDocCTtachmentView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = BNDPFRegularFont(14);
        _titleLabel.textColor = UIColorWithHex(0x51555D);
        _titleLabel.text = @"附件：";
        _titleLabel.numberOfLines = 1;
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(16);
            make.top.mas_equalTo(self.mas_top).offset(0);
        }];
        
        
        [LVUIUtils addLineInView:self top:NO leftMargin:16 rightMargin:16];
    }
    
    return self;
}

- (void)setModel:(BNDOfficeDocModel *)model
{
    _model = model;
    if (model.attachmentArray.count ==0) {
        UIView *lineView = [[UIView alloc] init];
        [self addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).offset(0);
            make.right.mas_equalTo(self.mas_right).offset(0);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(0);
            make.height.mas_equalTo(16);
            make.bottom.mas_equalTo(self.mas_bottom).offset(0);
        }];
    }else{
        _pdfListData = [NSMutableArray array];
        @weakify(self)
        [model.attachmentArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            @strongify(self)
            BNDCTtachmentView *pdfView = [[BNDCTtachmentView alloc] init];
            pdfView.fileInfo = obj;
            [self addSubview:pdfView];
            [self.pdfListData addObject:pdfView];
            if (idx==model.attachmentArray.count-1) {
                [pdfView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(self.mas_left).offset(16);
                    make.right.mas_equalTo(self.mas_right).offset(-128);
                    make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8*(idx+1)+62*idx);
                    make.height.mas_equalTo(62);
                    make.bottom.mas_equalTo(self.mas_bottom).offset(-16);
                }];
            }else{
                [pdfView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(self.mas_left).offset(16);
                    make.right.mas_equalTo(self.mas_right).offset(-128);
                    make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8*(idx+1)+62*idx);
                    make.height.mas_equalTo(62);
                }];
            }
        }];
    }
}
@end
